package com.kqb.autoconfigure;

import com.auth0.jwt.JWT;
import com.kqb.token.TokenTemplate;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * @author 杉果树皮
 * @date 2025/2/12 17:11
 * @description:
 */
@AutoConfiguration
@ConditionalOnClass(JWT.class)
@ConditionalOnProperty(prefix = "token", name = "enable", matchIfMissing = true)
@EnableConfigurationProperties(TokenProperties.class)
public class TokenAutoConfigure {

    @Bean
    @ConditionalOnMissingBean(TokenTemplate.class)
    public TokenTemplate tokenTemplate(TokenProperties tokenProperties) {
        TokenTemplate tokenTemplate = new TokenTemplate(tokenProperties);
        return tokenTemplate;
    }

}
